<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            width: 100px;
            height: 50px;
            border: 1px solid greenyellow;
        }
    </style>
</head>
<body>
<div>

</div>
<script>
    console.log(window)
    onkeypress = () => {
        const xhr = new XMLHttpRequest()
        xhr.open('post', 'http://127.0.0.1:8000/server/json')
        xhr.send()
        // 响应类型为json，可以自动帮我们 JSON.parse()
        xhr.responseType = 'json'
        xhr.onreadystatechange = ()=>{
            if (xhr.readyState===4){
                if (xhr.status>=200&&xhr.status<300){
                    console.log(xhr)
                    document.getElementsByTagName('div')[0].innerHTML = xhr.response.name
                }
            }
        }
    }
</script>
</body>
</html>